<div class="setting nomenu">
    <div class="right" style="width:700px;margin-right:70px;padding-left:50px;">
        <div class="workmodify">
            <div class="info">
                <span class="username">经纪人:</span>
                <span><?=$work['username']?></span>
            </div>
            <div class="info">
                <span class="title">是否暂定:</span>
                <select id="sure" class="select text hover flg">
                    <option value="0" <?php if($work['sure'] == 0){ ?>selected="selected"<?php }?>>否</option>
                    <option value="1" <?php if($work['sure'] == 1){ ?>selected="selected"<?php }?>>是</option>
                </select>
            </div>
            <div class="info">
                <span class="title">工作日期:</span>
                <input id="starttime" class="time text hover" type="text" value="<?=Model_Common::getFormatTimeYMD($work['starttime'])?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn',onpicked:ajaxtimechange})" />
                <span class="fromto">至</span>
                <input id="endtime" class="time text hover" type="text" value="<?=Model_Common::getFormatTimeYMD($work['endtime'])?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn',onpicked:ajaxtimechange})" />
            </div>
            <div class="info">
                <span class="title">工作时间:</span>
                <select id="starthour" class="select hour text hover" onchange="ajaxtimechange()">
                    <?php for($hour = 0; $hour <=23; $hour++){?>
                    <option value="<?=$hour?>" <?php if($hour == $work['starthour']){?>selected="selected"<?php }?>><?=$hour?></option>
                    <?php }?>
                </select>
                <select id="startmin" class="select text hover hour" onchange="timechange()">
                    <option value="0" <?php if(0 == $work['startmin']){?>selected="selected"<?php }?>>0</option>
                    <option value="15" <?php if(15 == $work['startmin']){?>selected="selected"<?php }?>>15</option>
                    <option value="30" <?php if(30 == $work['startmin']){?>selected="selected"<?php }?>>30</option>
                    <option value="45" <?php if(45 == $work['startmin']){?>selected="selected"<?php }?>>45</option>
                </select>
                <span class="fromto">至</span>
                <select id="endhour" class="select text hover hour" onchange="ajaxtimechange()">
                    <?php for($hour = 0; $hour <=23; $hour++){?>
                    <option value="<?=$hour?>" <?php if($hour == $work['endhour']){?>selected="selected"<?php }?>><?=$hour?></option>
                    <?php }?>
                </select>
                <select id="endmin" class="select text hover hour" onchange="timechange()">
                    <option value="0" <?php if(0 == $work['endmin']){?>selected="selected"<?php }?>>0</option>
                    <option value="15" <?php if(15 == $work['endmin']){?>selected="selected"<?php }?>>15</option>
                    <option value="30" <?php if(30 == $work['endmin']){?>selected="selected"<?php }?>>30</option>
                    <option value="45" <?php if(45 == $work['endmin']){?>selected="selected"<?php }?>>45</option>
                </select>
            </div>
            <div class="info">
                <span class="title">项目选择:</span>
                <select id="flg" class="select flg text hover" onchange="ajaxtimechange()">
                    <option value="1" <?php if($work['flg'] == 1){ ?>selected="selected"<?php }?>>面试</option>
                    <option value="2" <?php if($work['flg'] == 2){ ?>selected="selected"<?php }?>>工作</option>
                </select>
            </div>
            <div class="info">
                <span class="title long">本公司模特:</span>
                <div id="modelwrapper" class="modelwrapper">
                </div>
            </div>
            <div class="info">
                <span class="title floatleft long1">非本公司资源:</span>
                <textarea id="info" class="multtext"><?=$work['info']?></textarea>
            </div>
            <div class="info nodisplay">
                <span class="title floatleft">特别说明:</span>
                <textarea id="notice" class="multtext"><?=$work['notice']?></textarea>
            </div>
            <div class="info">
                <span class="title">工作类型:</span>
                <select id="worktype" class="select text hover type">
                    <?php foreach($workType as $key=>$value){?>
                    <option value="<?=$key?>" <?php if($work['worktype'] == $key){?>selected="selected"<?php }?>><?=$value?></option>
                    <?php }?>
                </select>
            </div>
            <div class="info">
                <span class="title">收费单价:</span>
                <input id="perprice" class="text text_middle" type="text" value="<?=$work['perprice']?>" />
            </div>
            <div class="info">
                <span class="title long1">预计小时人数:</span>
                <input id="hour" class="text text_middle" type="text" value="<?=$work['hour']?>" />
            </div>
            <div class="info">
                <span class="title long1">预计回款日期:</span>
                <input id="prepricetime" class="text time hover" type="text" value="<?=Model_Common::getFormatTimeYMD($work['prepricetime'])?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
            </div>
            <div class="info">
                <span class="title">客户名称:</span>
                <input id="companyname" class="text text_middle" type="text" value="<?=$work['companyname']?>" />
            </div>
            <div class="info">
                <span class="username long">客户联系人:</span>
                <input id="customername" class="text text_middle" type="text" value="<?=$work['customername']?>" />
            </div>
            <div class="info">
                <span class="username">手机号:</span>
                <input id="customertel" class="text text_middle" type="text" value="<?=$work['customertel']?>" />
            </div>
            <div class="info">
                <span class="title long1">其它联系方式:</span>
                <input id="customerothertel" class="text text_middle" type="text" value="<?=$work['customerothertel']?>" />
            </div>
            <div class="info">
                <span class="title floatleft">客户地址:</span>
                <textarea id="customeraddress" class="multtext"><?=$work['customeraddress']?></textarea>
            </div>
            <div class="info">
                <span class="title floatleft">工作地点:</span>
                <textarea id="workaddress" class="multtext"><?=$work['workaddress']?></textarea>
            </div>
            <?php if(Model_User::getLevelID() == 5){?>
             <div class="info">
                <span class="title long1">实际回款金额:</span>
                <input id="price" class="text text_middle" type="text" value="<?=$work['price']?>" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title long1">实际回款日期:</span>
                <?php if($work['pricetime'] != 0){ ?>
                <input id="pricetime" class="text time hover" type="text" value="<?=Model_Common::getFormatTimeYMD($work['pricetime'])?>" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
                <?php }else{?>
                <input id="pricetime" class="text time hover" type="text" value="" onClick="WdatePicker({readOnly:true,lang:'zh-cn'})" />
                <?php }?>
            </div>
            <div class="info">
                <span class="title short">成本:</span>
                <input id="cost" class="text text_middle" type="text" value="<?=$work['cost']?>" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title short">税款:</span>
                <input id="tax" class="text text_middle" type="text" value="<?=$work['tax']?>" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title short">提成:</span>
                <input id="pay" class="text text_middle" type="text" value="<?=$work['pay']?>" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title">客户返款:</span>
                <input id="ret" class="text text_middle" type="text" value="<?=$work['ret']?>" onkeyup="pricechange();" />
            </div>
            <div class="info">
                <span class="title short">利润:</span>
                <input id="profit" class="text text_middle" type="text" value="<?=$work['profit']?>" />
            </div>
            <?php }?>
            <div class="errmsg" id="errmsg"></div>
            <div class="info">
            	<input  class="btn btn_add btn_input return" type="button" onclick="window.location.href='<?=$ref?>'" value="返 回">
                <input id="modeladd" class="btn btn_input modify" type="button" value="确 认 修 改">
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
	timechange("<?=$work['modelids']?>");
    function ajaxtimechange(){
    	 var modelname = "";
         $(":checkbox:checked").each(function(){
             modelname += "," + $(this).val();
         });
         timechange(modelname);
    }
	function timechange(modelname){
		$.ajax({
	        url: "http://<?=HOST?>/work/doTimeChange",
	        cache: false,
	        timeout:10000,
	        type: "POST",
	        data: {
	        	flg:$("#flg").val(),
	            starttime:$("#starttime").val(),
	            endtime:$("#endtime").val(),
	            starthour:$("#starthour").val(),
	            endhour:$("#endhour").val(),
	            startmin:$("#startmin").val(),
                endmin:$("#endmin").val(),
	            modelids:modelname,
	            workid:<?=$work['workid']?>
	        },
	        dataType: "json",
	        beforeSend: function() {
	        	$("#modelwrapper").html("<span style='margin-top:5px;color:#FF0000'>加载中...</span>");
	        },
	        success: function(data) {
	                $("#modelwrapper").html(data.errMsg);
	        },
	        error:function(){
	        	$("#modelwrapper").html("<span style='margin-top:5px;color:#FF0000'>加载出错</span>");
	        }
	      });
	}
	function pricechange()
    {
        total = $("#price").val() - $("#cost").val() - $("#tax").val() - $("#pay").val() - $("#ret").val();
		if(isNaN(total)){
			alert('回款、成本、税款、提成和返款只能是数字');
		}
        $("#profit").val(total);
    }
    $("#modeladd").click(function(){
        $("#errmsg").text("");
        var modelname = "";
        $(":checkbox:checked").each(function(){
            modelname += "," + $(this).val();
        });

        $.ajax({
              url: "http://<?=HOST?>/work/doModify",
              cache: false,
              timeout:10000,
              type: "POST",
              data: {
                workid:<?=$work['workid']?>,
                		sure:$("#sure").val(),
                        starttime:$("#starttime").val(),
                          endtime:$("#endtime").val(),
                          starthour:$("#starthour").val(),
                          endhour:$("#endhour").val(),
                          startmin:$("#startmin").val(),
                          endmin:$("#endmin").val(),
                          flg:$("#flg").val(),
                          modelid:modelname,
                          info:$("#info").val(),
                          notice:$("#notice").val(),
                          worktype:$("#worktype").val(),
                          perprice:$("#perprice").val(),
                          price:$("#price").val(),
                          pricetime:$("#pricetime").val(),
                          customername:$("#customername").val(),
                          customertel:$("#customertel").val(),
                          customerothertel:$("#customerothertel").val(),
                          customeraddress:$("#customeraddress").val(),
                          workaddress:$("#workaddress").val(),
                          customername:$("#customername").val(),
                          hour:$("#hour").val(),
                          prepricetime:$("#prepricetime").val(),
                          companyname:$("#companyname").val(),
                          cost:$("#cost").val(),
                          tax:$("#tax").val(),
                          pay:$("#pay").val(),
                          ret:$("#ret").val(),
                          profit:$("#profit").val()
              },
              dataType: "json",
              beforeSend: function() {
                  disableHTML(true, '请稍等，处理中……', true);
              },
              success: function(data) {
                  if(data.errCode != 0){
                      disableHTML(true, data.errMsg, false);
                      setTimeout(disableHTML,2000);
                        $("#errmsg").text(data.errMsg);
                  }else{
                      disableHTML(true, '修改成功，跳转中……', true);
                      setTimeout("location.href = 'http://<?=HOST?>/work/detail/workid/<?=$work['workid']?>'", 500);
                  }
              },
              error:function(){
                      disableHTML(true, "请求出错，请重试或联系系统管理员", false);
                      setTimeout(disableHTML,2000);
                  }
            });
    });
</script>
